package com.ls.sort;

import org.junit.Test;

import java.util.ArrayList;
import java.util.HashMap;

/**
 * @author : 梁苏
 * @date : 2023/3/21 11:44
 **/
public class BitTest {

    public static void main(String[] args) {

    }

    @Test
    public void move(){
        // 移位操作
        // 移位1: 1
        // 移位2: 10
        // 移位3: 100
        int pos = 0;
        byte pb = (byte)(1 << pos);
        System.out.println(pb);
    }

    @Test
    public void aa(){
        int a = 10;
        System.out.println(tableSizeFor(1));
        System.out.println(tableSizeFor(3));
        System.out.println(tableSizeFor(10));
        System.out.println(tableSizeFor(16));
        System.out.println(tableSizeFor(31));
        System.out.println(tableSizeFor(32));
    }

    static final int tableSizeFor(int cap) {
        int n = cap - 1;
        n |= n >>> 1;
        n |= n >>> 2;
        n |= n >>> 4;
        n |= n >>> 8;
        n |= n >>> 16;
        n = (n < 0) ? 1 : n + 1;
        n = n / 8;
        return n <= 0 ? 1 : n;
    }

}
